<?php

namespace process;

use app\common\enum\CrontabEnum;
use Workerman\Crontab\Crontab;
use app\common\logic\CrontabLogic;
use app\common\model\Crontab as CrontabModel;

class Task
{
    public function onWorkerStart()
    {
        $logic = new CrontabLogic();
        $taskList = CrontabModel::where('status', CrontabEnum::START)->select();

        foreach ($taskList as $item) {
            new Crontab($item->expression, function () use ($logic, $item) {
                $logic->run($item->id);
            });
        }
    }
}
